package Dao;

import bean.*;

import java.util.List;

public class check_recordDao extends BaseDao{
    public List<check_record> queryRecords() throws Exception {
        String sql = "SELECT * FROM check_appointment";
        return queryForList(check_record.class,sql);
    }

    public int addRecord(check_record record) {
        String sql = "INSERT INTO check_appointment(appointment_date,appointment_time,patient_name,patient_gender,patient_age,examination_name,doctor_name, appointment_status,created_time,IdNumber) VALUES(?,?,?,?,?,?,?,?,?,?)";
        try {
            return update(sql,record.getAppointment_date(),record.getAppointment_time(),record.getPatient_name(),record.getPatient_gender(),record.getPatient_age(),record.getExamination_name(),record.getDoctor_name(),record.getAppointment_status(),record.getCreated_time(),record.getIdNumber());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    public int deleteRecordBYId(Integer id) {
        String sql = "DELETE FROM check_appointment WHERE check_id= ?";
        try {
            return update(sql,id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public check_record queryRecordBYId(Integer id) {
        String sql = "SELECT check_id,appointment_date,appointment_time,patient_name,patient_gender,patient_age,examination_name,doctor_name, appointment_status,created_time,IdNumber FROM check_appointment WHERE check_id= ?";
        try {
            return queryForOne(check_record.class,sql,id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public List<check_record> queryRecordBYStatus(String status) {
        String sql = "SELECT check_id,appointment_date,appointment_time,patient_name,patient_gender,patient_age,examination_name,doctor_name, appointment_status,created_time,IdNumber FROM check_appointment WHERE appointment_status  = ?";
        try {
            return queryForList(check_record.class,sql,status);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
